package com.flxz.aiaccount.controller;

import com.flxz.aiaccount.dto.ParseRequest;
import com.flxz.aiaccount.dto.ParseResponse;
import com.flxz.aiaccount.service.AiParseService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * AI 记账解析接口
 */
@RestController
@RequestMapping("/user/ai")
public class AiParseController {

    @Resource
    private AiParseService aiParseService;

    /**
     * 解析用户自然语言为记账结构
     */
    @PostMapping(value = "/parse-transaction", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String, Object> parse(@RequestBody ParseRequest request) {
        ParseResponse result = aiParseService.parseText(request);
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("msg", "success");
        response.put("data", result);
        return response;
    }
}


